package com.example.boot.dlgoods.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.boot.dlgoods.service.DlGoodsService;
import com.example.boot.util.ResultData;
import com.example.boot.util.ResultUtil;

@RestController
public class DlGoodsController {
	private final static Logger logger = LoggerFactory.getLogger(DlGoodsController.class);

	@Autowired
	private DlGoodsService dlGoodsService;

	/**
	 * 首页分页商品
	 * 
	 * @param page
	 * @param size
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "pageing/goods")
	public ResultData<Object> pagingGoods(@RequestParam(value = "page", required = true) Integer page,
			@RequestParam(value = "size", required = true) Integer size) throws Exception {
		logger.info("加载分页,page={}|size={}|", page, size);
		return ResultUtil.success(dlGoodsService.pagingGoods(page, size));
	}

	/**
	 * 商品详情
	 * @param goodsId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "load/goods")
	public ResultData<Object> loadGoodsData(@RequestParam(value = "goodsId", required = true) String goodsId)
			throws Exception {
		logger.info("查找商家详情, goodsId={}|", goodsId);
		return ResultUtil.success(dlGoodsService.byIdFindGoods(goodsId));

	}
}
